<?php

// 广告位表

namespace app\console\model;
use think\Db;
use think\Model;
use think\Request;
use app\common\trilateral\Classify as ClassifyAlias;
use think\Session;
use think\Hook;

class News1 extends Model
{
    // 模型事件
    protected static function init()
    {
        self::event('before_insert', function ($data) {
           $data->create_time = date('Y-m-d H:i:s',time());
           $data->update_time = date('Y-m-d H:i:s',time());
           $data->create_id = Session::get('manage_id');
           $data->reason = '';
        });

        self::event('before_update', function ($data) {
            $data->update_time = date('Y-m-d H:i:s',time());
            $data->reason = '';
        });

        self::event('before_write', function ($data) {
            $data->pic_url = uploadImg('pic_url');
            if($data->auding_status == 1){
                $data->auding_id = Session::get('manage_id');
                $data->reason = '';
                $data->auding_time = date('Y-m-d H:i:s',time());
            }
            if($data->auding_status == 2){
                $data->auding_id = Session::get('manage_id');
                $data->auding_time = date('Y-m-d H:i:s',time());
                $data->reason = '';
            }
            if($data->auding_status == 3){
                $data->auding_id = Session::get('manage_id');
                $data->auding_time = date('Y-m-d H:i:s',time());
            }
        });
    }

    protected function base($query)
    {
        $query->where('is_delete',1);
    }

    public function getAudingTextAttr($value, $data)
    {
        $status = [1 => '等待审核', 2 => '审核成功', 3 => '审核失败'];
        return $status[$data['auding_status']];
    }

    public function getAudingManageAttr($value, $data)
    {
       $ret = Db::name('manager')->where('id',$data['auding_id'])->value('username');
        return $ret;
    }

    public function getCreateManageAttr($value, $data)
    {
        $ret = Db::name('manager')->where('id',$data['create_id'])->value('username');
        return $ret;
    }
    public function getNewsTypeAttr($value, $data)
    {
        $ret = Db::name('news_type')->where('id',$data['type_id'])->value('type_name');
        return $ret;
    }

}